/*
    This file is part of the open source IVMP-MySQL project.

    IVMP-MySQL is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    IVMP-MySQL is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with IVMP-MySQL.  If not, see <http://www.gnu.org/licenses/>.
*/

/*
	File: Functions.h

	Description:
		Declares all of the functions that will be registered within Squirrel. Also
		defines some key macros that will be needed.
*/

#ifndef IVMP_MYSQL_FUNCTIONS_H
#define IVMP_MYSQL_FUNCTIONS_H

#include <SDK/SDK.h>
#include <SDK/Squirrel.h>

// == SQUIRREL MACROS == //
#define CHECK_PARAMS(count) \
	int numparams = sq_gettop(S); \
	if(numparams <= count) \
	{ \
		LogPrintf("[MySQL] Error: Invalid Parameter count, got %d, need %d.", numparams - 1, count); \
		sq_pushbool(S, false); \
		return 1; \
	}

#define GET_PARAMCOUNT() \
	sq_gettop(S)

#define GET_STRING(idx, to) \
	sq_getstring(S, idx + 1, &to)

#define GET_INTEGER(idx, to) \
	sq_getinteger(S, idx + 1, &to)

#define GET_BOOLEAN(idx, to) \
	sq_getbool(S, idx + 1, &to)

#define GET_FLOAT(idx, to) \
	sq_getfloat(S, idx + 1, &to)

#define GET_USERPOINTER(idx, to) \
	sq_getuserpointer(S, idx + 1, &to)

#define SQUIRREL_FUNC(function) \
	int function(HSQUIRRELVM S);
// == END SQUIRREL MACROS == //

// Usage: mysql_debug(1) to enable logging
SQUIRREL_FUNC(plugin_mysql_debug);

// Usage: mysql_connect(host, username, password, database, port = 3306)
SQUIRREL_FUNC(plugin_mysql_connect);

// Usage: mysql_close(handle)
SQUIRREL_FUNC(plugin_mysql_close);

// Usage: mysql_errno(handle)
SQUIRREL_FUNC(plugin_mysql_errno);

// Usage: mysql_ping(handle)
SQUIRREL_FUNC(plugin_mysql_ping);

// Usage: mysql_query(handle, query)
SQUIRREL_FUNC(plugin_mysql_query);

// Usage: mysql_store_result(handle)
SQUIRREL_FUNC(plugin_mysql_store_result);

// Usage: mysql_free_result(handle)
SQUIRREL_FUNC(plugin_mysql_free_result);

// Usage: mysql_num_rows(handle)
SQUIRREL_FUNC(plugin_mysql_num_rows);

// Usage: mysql_num_fields(handle)
SQUIRREL_FUNC(plugin_mysql_num_fields);

// Usage: mysql_fetch_row(handle)
SQUIRREL_FUNC(plugin_mysql_fetch_row);

// Usage: mysql_fetch_field_row(handle, fieldIndex)
SQUIRREL_FUNC(plugin_mysql_fetch_field_row);

// Usage: mysql_escape_string(handle, string)
SQUIRREL_FUNC(plugin_mysql_escape_string);

#endif